#!/bin/bash - 
#===============================================================================
#
#          FILE:  kousuan.sh
# 
#         USAGE:  ./kousuan.sh 
# 
#   DESCRIPTION:  l 30 page i 50 per/page  j1,j2 1-99+- j1,j2 1-9 */
#                 k 1-4 +-*/
#                 m 5 per line
#       OPTIONS:  ---
#  REQUIREMENTS:  ---
#          BUGS:  ---
#         NOTES:  ---
#        AUTHOR: YOUR NAME (), 
#       COMPANY: 
#       CREATED: 2019年01月28日 12时48分11秒 CST
#      REVISION:  ---
#===============================================================================

set -o nounset                              # Treat unset variables as an error
#fucnion #
function rand3(){
    min=$1
    max=$(($2-$min+1))
    num=$(cat /dev/urandom | head -n 10 | cksum | awk -F ' ' '{print $1}')
    echo $(($num%$max+$min))
}
function rand2(){
        min=$1
        max=$(($2-$min+1))
        num=$(date +%s%N)
        echo $(($num%$max+$min))  
    }

#    rnd=$(rand 1 50)  
#    echo $rnd 
function rand(){
        min=$1
        max=$(($2-$min+1))
        echo $(($RANDOM%$max+$min))  
    }

#--------logic-----------#
m=4
for l in $(seq 1 30)
do
n=0
j0=0
for i in $(seq 1 52)
do
        k=$(rand 1 4)
        # current rep / with *
        if [ "$k" = "4" ] ; then
                k=3
        fi
        case  "$k" in
                1) op="+";;
                2) op="-";;
                3) op="X";;
                4) op="/";;
        esac

        if [ "$k" = "3" ] ; then
                j1=$(rand3 1 9)
                j2=$(rand2 2 9)
                if [ "$j0" = "$j1" ] ; then
                        j1=$(rand 1 9)
                fi
                j0=$j1
        else
                j1=$(rand3 9 99)
                j2=$(rand2 9 99)
                if [ "$j0" = "$j1" ] ; then
                        j1=$(rand 9 99)
                fi
                j0=$j1
                if [ "$k" = "2" ] ; then
                        if [ $j1 -lt $j2 ];then
                                t=$j1
                                j1=$j2
                                j2=$t
                        fi
                elif  [ "$k" = "1" ] ; then
                        while [ $[$j1 + $j2] -gt 100 ]; do
                                if [ $j1 -gt 50 ];then
                                        j1=$[$j1-50];
                                elif [ $j2 -gt 50 ];then
                                        j2=$[$j2-50];
                                fi
                        done
                fi
        fi
        n=$[$n+1];
        if [ "$n" = "$m" ] ; then
                n=0;
                echo -e "$j1 $op $j2 =  \t "
                echo  ""
        else

                echo -e -n "$j1 $op $j2 =  \t "
        fi
done
        echo  ""
done
